function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

function isNaturalNumber( sText ) {
    var re = /^[\d]+$/;
	return re.test( sText );
}

function isIntNumber( sText ) {
    if( sText.toString( ) == '-0' ) return false;
	
	var re = /^\-?[\d]+$/;
	return re.test( sText );
	
}
 
function isFloatNumber( sText ) {
	if( sText.toString( ) == '-0' ) return false;
	
	var re = /^\-?[\d]+$/;
	if( re.test( sText ) ) return true;
	re = /^\-?[\d]+\.[\d]+$/;
	return re.test( sText );
} 

function isEmpty( sText ) {
	if( sText ) return false;
    
	return true;
}

function isNumberFormat( sText, sFormat ) {
	var specCharPattern = /[\D]/;
	var specChar = sFormat.match( specCharPattern );
	var aNum = sFormat.split( specChar );
	
	var sCmd = "var re = /^";
	for( var iC = 0; iC < aNum.length; iC++ ) {
		if( iC != 0 )
			sCmd += "\\" + specChar; 
		sCmd += "[0-9]{" + aNum[iC] + "}";
	}
	sCmd += "$/;";
	eval( sCmd );
	return re.test( sText );
}
 
function isEmail( sText ) {
    var str = sText;
	if(str == "") {
        return false;
    }
    var re = /^[\w-_]+(\.[\w-_]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        return false;
    } else {
        return true;
    }
}


function stdzSlashes(dm) {
	var len = dm.elements.length;
	var i = 0;
	for(i = 0; i < len; i++) {
		if( dm.elements[i].value ) {
			dm.elements[i].value = dm.elements[i].value.replace(RegExp("\'{1}" , "g"), "\\\'");
		}
	}
	return true;
}


function addSlashes( sText ) {
	if( sText) {
		return sText.replace(/'|\\'/g, "\\'");
	} else
		return sText;
}

Array.prototype.in_array = function(p_val) {
	 for(var i = 0, l = this.length; i < l; i++) {
		  if(this[i] == p_val) {
			  return true;
		  }
	 }
	 return false;
}

// ex: arr.remove(value);
Array.prototype.remove= function(){
    var what, a= arguments, L= a.length, ax;
    while(L && this.length){
        what= a[--L];
        while((ax= this.indexOf(what))!= -1){
            this.splice(ax, 1);
        }
    }
    return this;
}


function urlencode (str) {
    str = (str + '').toString();
   
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}	
	
//remove arr by index
Array.prototype.removeAr = function(from, to) {
	  var rest = this.slice((to || from) + 1 || this.length);
	  this.length = from < 0 ? this.length + from : from;
	  return this.push.apply(this, rest);
}

//remove all element in array
var removeAll = function(array){
	if(array.length == 0) return;
	array.removeAr(0);
	removeAll(array);
}

function removeArrayElement(array, item){
    for(var i in array){
        if(array[i]==item){
            array.splice(i,1);
            break;
        }
    }
	return array;
}

function pausecomp(ms) {
	ms += new Date().getTime();
	while (new Date() < ms){}
} 

jQuery.fn.center = function() {
    return this.each(function(){
                var el = $(this);
                var h = el.height();
                var w = el.width();
                var w_box = $(window).width();
                var h_box = $(window).height(); 
                var w_total = (w_box - w)/2; //400
                var h_total = (h_box - h)/2;
                var css = {"position": 'absolute', "left": w_total+"px", "top":
h_total+"px"};
                el.css(css)
    });
};

function queryURL(url){
	window.location = url;
}

function reload(){
	window.location.reload();
}



(function( $ ){
	$.fn.serializeJSON=function() {
		var json = {};
		jQuery.map($(this).serializeArray(), function(n, i){
		json[n['name']] = n['value'];
	});
		return json;
	};
})( jQuery );
